#include<fstream>
#include<iostream>
#include<vector>
#include<string>
#include<time.h>
#include<sstream>
#include "CSpaceCharge.h"
using namespace std;
void RandCylinder(double,double);
void RandBall(double);
void RandSurface(double);
int main(int argc, char** argv)
{         
  time_t start,end;
  start=clock();
  RandBall(0.2);
  //=========================
  vector<vector<double> > vvdBeam;
  vector<double> vdTmp;
  double dTmp;
  stringstream ss;
  string sRow;
  ifstream infile("beam.txt");
    while(!infile.eof())
    {
      vdTmp.resize(0);;
      getline(infile,sRow);
      if(sRow=="") continue;
      ss.clear();
      ss<<sRow;
      while(ss>>dTmp)
      vdTmp.push_back(dTmp);
      vvdBeam.push_back(vdTmp);
    }
  //=====================================

  CSpaceCharge sp;
  double dFreq,dI,dPhis;
  int nr,nz,nx,ny;
  double dr,dz,dx,dy; 
  dI=30;dFreq=324;
  nr=16;nz=16;dr=0.02;dz=0.02;
  nx=7;ny=7;dx=0.04;dy=0.04;
  dPhis=-20;
  sp.InputStruct(dFreq);  //can not be omitted, now
//  sp.setFreq(dFreq);
  sp.setPhis(dPhis);
  sp.InputBeam(&vvdBeam,dI);
  sp.setFlag(0);
  sp.InGrid(nr,nz,dr,dz);
  sp.formGrid();
  sp.scheff(0);
  end=clock();
  cout<<"RUN TIME IS"<<(double)(end-start)/CLOCKS_PER_SEC<<" S "<<endl;
}
